------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure4.log
  log type:  text
 opened on:  14 Jan 2019, 15:45:21

. #delimit ;
delimiter now ;
. *     ***************************************************************** *;
. *     ***************************************************************** *;
. *       File-Name:      figure4.do                                      *;
. *       Date:           March 9, 2017                                   *;
. *       Author:         MRG/CC                                          *;
. *       Purpose:        Produce Figure 4 for It's Not Only What You     *;
. *                       Say, It's Also How You Say It: The Strategic    *;
. *                       Use Of Campaign Sentiment. Journal of Politics. *;
. *                       Forthcoming.                                    *;
. *           Input File:     sentiment.dta                                   *;
. *       Output File:    figure4.log                                     *;
. *       Data Output:    none                                            *;
.              *       Previous file:  sentiment.dta                                   *;
. *       Machine:        desktop/laptop                                                  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *        Load data                                                      *;
. *     ****************************************************************  *;
. use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

. set more off;

. *     ****************************************************************  *;
. *       Declare data to be panel, where the panel is based on language  *;
. *     ****************************************************************  *;
. xtset language;
       panel variable:  language (unbalanced)

. xtsum positive_sentiment;

Variable         |      Mean   Std. Dev.       Min        Max |    Observations
-----------------+--------------------------------------------+----------------
positi~t overall |  1.696912   1.446166       -.68        7.6 |     N =     421
         between |              1.34797   .4018627     4.3828 |     n =       7
         within  |             .7198334  -1.565888   4.914112 | T-bar = 60.1429

. *     ****************************************************************  *;
. *       Generate additional variables that we will need for our         *;
. *       analysis.                                                       *;
. *     ****************************************************************  *;
. gen incumbent_inflation_l = incumbent*inflation_l;
(21 missing values generated)

. label var incumbent_inflation "incumbent*inflation_l";

. gen incumbent_unemployment_l = incumbent*unemployment_l;
(7 missing values generated)

. label var incumbent_unemployment_l "incumbent*unemployment_l";

. gen incumbent_pm = incumbent*pm;

. label var incumbent_pm "incumbent*pm";

. gen incumbent_fm = incumbent*fm;

. label var incumbent_fm "incumbent*fm";

. gen left_right2=left_right*left_right;
(39 missing values generated)

. label var left_right2 "left_right*left_right";

. gen extremist = 0;

. replace extremist=1 if family_id ==14 | family_id==40;
(87 real changes made)

. replace extremist = . if family_id==.;
(9 real changes made, 9 to missing)

. label var extremist "1 if communist/socialist or far right, 0 otherwise";

. gen extremist2 = 0;

. replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
(124 real changes made)

. replace extremist2 = . if family_id==.;
(9 real changes made, 9 to missing)

. label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";

. gen extremist_inflation_l=extremist*inflation_l;
(30 missing values generated)

. label var extremist_inflation "extremist*inflation_l";

. gen extremist_unemployment_l=extremist*unemployment_l;
(16 missing values generated)

. label var extremist_unemployment_l "extremist*unemployment_l";

. tabulate language, gen(l);

   language |      Freq.     Percent        Cum.
------------+-----------------------------------
      Dutch |        102       24.23       24.23
    English |         85       20.19       44.42
     French |         36        8.55       52.97
     German |         46       10.93       63.90
    Italian |         54       12.83       76.72
 Portuguese |         50       11.88       88.60
    Spanish |         48       11.40      100.00
------------+-----------------------------------
      Total |        421      100.00

. *     ****************************************************************  *;
. *      Change graph scheme                                                  *;
. *     ****************************************************************  *;
. ssc install scheme-burd, replace;
checking scheme-burd consistency and verifying not already installed...
all files already exist and are up to date.

. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *       Produce Figure 4                                                *;
. *     ****************************************************************  *;
. *     ****************************************************************  *;
. *reg positive_sentiment incumbent incumbent_pm left_right left_right2 l1 l3 l4 l5 l6 l7, cluster(election_id);
. bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm left_right left_right2, fe;
(running xtreg on estimation sample)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400

Fixed-effects (within) regression               Number of obs      =       382
Group variable: language                        Number of groups   =         7

R-sq:  within  = 0.1817                         Obs per group: min =        35
       between = 0.0954                                        avg =      54.6
       overall = 0.0675                                        max =        90

                                                Wald chi2(4)       =     91.61
corr(u_i, Xb)  = 0.0652                         Prob > chi2        =    0.0000

                            (Replications based on 69 clusters in election_id)
------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
positive_s~t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
   incumbent |   .1545325   .0637387     2.42   0.015     .0296071     .279458
incumbent_pm |    .239634   .0733366     3.27   0.001     .0958969    .3833711
  left_right |   .4104397   .0690804     5.94   0.000     .2750446    .5458347
 left_right2 |  -.0376656   .0069866    -5.39   0.000    -.0513591   -.0239722
       _cons |   .7746918   .1390328     5.57   0.000     .5021925    1.047191
-------------+----------------------------------------------------------------
     sigma_u |  1.3907853
     sigma_e |  .62788657
         rho |  .83069045   (fraction of variance due to u_i)
------------------------------------------------------------------------------

. preserve;

. set obs 10000;
number of observations (_N) was 421, now 10,000

. set seed 10101;

. drawnorm MG_b1-MG_b5, n(10000) means(e(b)) cov(e(V)) clear;
(obs 10,000)

. postutil clear;

. postfile mypost y_hat lo hi using "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sim.dta", replace;

. noisily display "start";
start

. local a=0 ;

. while `a' <= 10 { ;
  2. {;
  3. scalar h_constant=1;
  4. generate y  = MG_b5*h_constant + MG_b3*`a' + MG_b4*`a'*`a';
  5. egen yhat = mean(y);
  6. tempname y_hat lo hi;
  7. _pctile y, p(2.5,97.5);
  8. scalar `lo' = r(r1);
  9. scalar `hi' = r(r2);
 10. scalar `y_hat'=yhat;
 11. post mypost (`y_hat') (`lo') (`hi');
 12. };
 13. drop y yhat;
 14. local a=`a'+ 0.001;
 15. display "." _c;
 16. } ;
................................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..............................................................................................................................................
> ..........................................................
. display "";


. postclose mypost;

. restore;

. merge using "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sim.dta";
(note: you are using old merge syntax; see [D] merge for new syntax)

. gen MV=(_n-1)/1000;

. replace MV=. if _n>10000;
(0 real changes made)

. ssc install scheme-burd, replace;
checking scheme-burd consistency and verifying not already installed...
all files already exist and are up to date.

. graph twoway hist left_right, percent lcolor(white) color(gs13) yaxis(2)
>     || line y_hat MV, lwidth(medthick) clpattern(solid) color(black)
>     || line lo MV, clpattern(longdash) clwidth(thin) clcolor(ebblue)
>     || line hi MV, clpattern(longdash) clwidth(thin) clcolor(ebblue)
>     ||,
>     xlabel(0 1 2 3 4 5 6 7 8 9 10, nogrid labsize(2.5))
>     ylabel(0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2, axis(1) nogrid labsize(2.5))
>     ylabel(0 5 10 15 20, tlcolor(gs13) labcolor(gs13) axis(2) nogrid labsize(2.5))
>     yscale(noline alt) yscale(noline alt axis(2)) xscale(noline) legend(off)
>     ytitle("Positive Sentiment", size(3))
>     ytitle("Percentage of Observations", color(gs12) axis(2) size(3))
>     title("", size(3)) subtitle("", size(3)) xtitle("Left-Right Position", size(3)) xscale(titlegap(2)) yscale(titlegap(2)) scheme(burd);

.         graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig4.pdf", replace;
(file C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig4.pdf written in PDF format)

. *     ****************************************************************  *;
. *       Replication complete                                            *;
. *     ****************************************************************  *;
. log close;
      name:  <unnamed>
       log:  C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure4.log
  log type:  text
 closed on:  14 Jan 2019, 15:46:51
------------------------------------------------------------------------------------------------------------------------------------------------
